/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.belfalas.simy86;

import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author belfalas
 */
public class ReadFile {
    
    public static void parse(File file, Y86 y86){
        BufferedReader br = null;
        try {
            br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
            
            String linha;
            
            int position = 0;
            
            while ((linha = br.readLine())!=null){
                if (linha.charAt(0) == '@'){
                    position = Integer.parseInt(linha.substring(2), 16);
                    continue;
                }
                if (linha.charAt(0) == '#'){
                    continue;
                }
                Y86.memoria.writeUnsignedByte(Short.parseShort(linha.trim(), 16), position++);
            }                    
            
        } catch (IOException ex) {
            Logger.getLogger(ReadFile.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                br.close();
            } catch (IOException ex) {
                Logger.getLogger(ReadFile.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
